package com.bjx.common.security.interceptor;

import cn.dev33.satoken.same.SaSameUtil;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

@Component
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header(SaSameUtil.SAME_TOKEN,SaSameUtil.getToken());
        SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
        if(ObjectUtil.isNotEmpty(tokenInfo) && StrUtil.isNotEmpty(tokenInfo.getTokenValue())){
            requestTemplate.header(tokenInfo.getTokenName(),tokenInfo.getTokenValue());
        }
    }
}
